package com.yuhang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuhang.entity.HyAdmin;
import com.yuhang.entity.HyRepair;
import com.yuhang.entity.HyUser;
import com.yuhang.mapper.HyAdminMapper;
import com.yuhang.mapper.HyRepairMapper;
import com.yuhang.mapper.HyUserMapper;
import com.yuhang.service.HyAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuhang
 * @since 2021-03-11
 */
@Service
public class HyAdminServiceImpl extends ServiceImpl<HyAdminMapper, HyAdmin> implements HyAdminService {

    @Autowired
    private HyAdminMapper hyAdminMapper;
    @Autowired
    private HyRepairMapper hyRepairMapper;
    @Autowired
    private HyUserMapper hyUserMapper;

    @Override
    public IPage<HyAdmin> selectByPage(int pageNum, int pageSize, String username) {
        Page<HyAdmin> page = new Page(pageNum,pageSize);
        QueryWrapper<HyAdmin> qw = new QueryWrapper();
        if(username!=null&&!username.equals("")){
            qw.like("username",username);
        }
        IPage<HyAdmin> hyAdminIPage = hyAdminMapper.selectPage(page,qw);
        return hyAdminIPage;
    }

    @Override
    public Boolean selectByUsername(String username) {
        int state=0;
        QueryWrapper<HyAdmin> qw1 = new QueryWrapper();
        qw1.eq("username",username);
        HyAdmin hyAdmin = hyAdminMapper.selectOne(qw1);
        QueryWrapper<HyRepair> qw2 = new QueryWrapper();
        qw2.eq("username",username);
        HyRepair hyRepair = hyRepairMapper.selectOne(qw2);
        QueryWrapper<HyUser> qw3 = new QueryWrapper();
        qw3.eq("username",username);
        HyUser hyUser = hyUserMapper.selectOne(qw3);
        if(hyAdmin==null&&hyRepair==null&&hyUser==null){
            state=1;
        }
        if(state==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean selectByUser(String username) {
        QueryWrapper<HyUser> qw3 = new QueryWrapper();
        qw3.eq("username",username);
        HyUser hyUser = hyUserMapper.selectOne(qw3);
        if(hyUser==null){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean selectByRepair(String username) {
        QueryWrapper<HyRepair> qw2 = new QueryWrapper();
        qw2.eq("username",username);
        HyRepair hyRepair = hyRepairMapper.selectOne(qw2);
        if(hyRepair==null){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean selectByAdmin(String username) {
        QueryWrapper<HyAdmin> qw1 = new QueryWrapper();
        qw1.eq("username",username);
        HyAdmin hyAdmin = hyAdminMapper.selectOne(qw1);
        if(hyAdmin==null){
            return true;
        }else {
            return false;
        }
    }

}
